package com.ymatou.iapi.godmch.testcase;

import net.sf.json.JSONObject;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.setCustomBuyerSharePicParametersBean;
import com.ymatou.iapi.godmch.service.setCustomBuyerSharePicParametersCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.godmch.biz_config;
import com.ymttest.database.model.godmch.biz_configExample;
import com.ymttest.database.sqlwapper.godmch.biz_configWapper;
import com.ymttest.utils.TestDataManager;
/**
*设置买家端店铺分享图自定义参数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_setCustomBuyerSharePicParameters{
	private static setCustomBuyerSharePicParametersBean bean;
	private static setCustomBuyerSharePicParametersCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置买家端店铺分享图自定义参数");
	}

	@Before
	public void caseUp() {
		bean=new setCustomBuyerSharePicParametersBean();
		call=new setCustomBuyerSharePicParametersCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setCustomBuyerSharePicParameters_001() {
		Logger.start(true,"设置买家端店铺分享图自定义参数-EnableCustom=true");
		try {
	        
			Integer mchId=TestDataManager.getRandomIntNum(5);
			bean.setMchId(mchId);
			bean.setEnableCustom(true);
			bean.setBasePicUrl("http://www.baidu.com/1123.jpg");
			bean.setWidth(10);
			bean.setX(20);
			bean.setY(30);
			bean.setCodeFontSize(8);
			bean.setCodeFontColor("#FFB6C1");
			bean.setCodeX(40);
			bean.setCodeY(50);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			biz_configWapper configWapper=new biz_configWapper();
			biz_configExample config=new biz_configExample();
			config.createCriteria().andBiz_idEqualTo(bean.getMchId()).andBiz_keyEqualTo("custom_buyer_pic");
			biz_config DB_config=configWapper.selectByExample(config).get(0);
			String biz_value=DB_config.getBiz_value();
			JSONObject job=JSONObject.fromObject(biz_value);
			Logger.verifyEquals(bean.getEnableCustom(), job.getBoolean("enableCustom"), "验证enableCustom");
			Logger.verifyEquals(bean.getBasePicUrl(), job.getString("basePicUrl"), "验证basePicUrl");
			Logger.verifyEquals(bean.getWidth(), job.getInt("width"), "width");
			Logger.verifyEquals(bean.getX(), job.getInt("x"), "验证x");
			Logger.verifyEquals(bean.getY(), job.getInt("y"), "验证y");
			Logger.verifyEquals(bean.getCodeFontSize(), job.getInt("codeFontSize"), "验证codeFontSize");
			Logger.verifyEquals(bean.getCodeFontColor(), job.getString("codeFontColor"), "验证codeFontColor");
			Logger.verifyEquals(bean.getCodeX(), job.getInt("codeX"), "验证codeX");
			Logger.verifyEquals(bean.getCodeY(), job.getInt("codeY"), "验证codeY");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setCustomBuyerSharePicParameters_002() {
		Logger.start(true,"设置买家端店铺分享图自定义参数-EnableCustom=false");
		try {
	        
			Integer mchId=TestDataManager.getRandomIntNum(5);
			bean.setMchId(mchId);
			bean.setEnableCustom(false);
			bean.setBasePicUrl("http://www.baidu.com/1123.jpg");
			bean.setWidth(10);
			bean.setX(20);
			bean.setY(30);
			bean.setCodeFontSize(8);
			bean.setCodeFontColor("#FFB6C1");
			bean.setCodeX(40);
			bean.setCodeY(50);
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("200", call.getStatus1(), "验证status");
			biz_configWapper configWapper=new biz_configWapper();
			biz_configExample config=new biz_configExample();
			config.createCriteria().andBiz_idEqualTo(bean.getMchId()).andBiz_keyEqualTo("custom_buyer_pic");
			biz_config DB_config=configWapper.selectByExample(config).get(0);
			String biz_value=DB_config.getBiz_value();
			JSONObject job=JSONObject.fromObject(biz_value);
			Logger.verifyEquals(bean.getEnableCustom(), job.getBoolean("enableCustom"), "验证enableCustom");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}